package org.example.pmsystem.controller;

import org.example.pmsystem.Response;
import org.example.pmsystem.entity.Interview;
import org.example.pmsystem.entity.Resume;
import org.example.pmsystem.service.InterviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:5173")
@RequestMapping("/interview")
public class InterviewController {
    @Autowired
    private InterviewService interviewService;
    @GetMapping("getAllInterview")
    public Response<List<Interview>> getAllInterview(){
        return Response.newSuccess(interviewService.getAllInterview());
    }

//    @GetMapping("selectResumeByInterNo/{interNo}")
//    public Response<Resume> selectResumeFileByInterNo(@PathVariable int interNo){
//        return Response.newSuccess(interviewService.selectResumeByInterNo(interNo));
//    }

//    @GetMapping("selectInterviewByDate/{date}")
//    public Response<List<Interview>> selectInterviewByDate(@PathVariable Date date){
//        return Response.newSuccess(interviewService.selectInterviewByDate(date));
//    }

    @GetMapping("getInterviewByPeriod/{period}")
    public Response<List<Interview>> getInterviewByPeriod(@PathVariable String period){
        return Response.newSuccess(interviewService.selectInterviewByPeriod(period));
    }

    @GetMapping("getInterviewByStatus/{status}")
    public Response<List<Interview>> getInterviewByStatus(@PathVariable String status){
        return Response.newSuccess(interviewService.selectInterviewByStatus(status));
    }

    @GetMapping("getInterviewByDep/{dep}")
    public Response<List<Interview>> getInterviewByDep(@PathVariable String dep){
        return Response.newSuccess(interviewService.selectInterviewByDep(dep));
    }

//    @GetMapping("getInterviewByPeriodAndStatus/period={period}&status={status}")
//    public Response<List<Interview>> selectInterviewByPeriodAndStatus(@PathVariable String period,@PathVariable String status){
//        return Response.newSuccess(interviewService.selectInterviewByPeriodAndStatus(period,status));
//    }

    @PostMapping("insertInterview")
    public Response<Boolean> insertinterview(@RequestBody Interview interview) {
        if (interviewService.insertInterview(interview))
            return Response.newSuccess(true);
        return Response.newFail("面试时间不正确！");
    }

    @PutMapping("updateinterview")
    public Response<Boolean> updateInterview(@RequestBody Interview interview) {
        if (interviewService.updateInterview(interview))
            return Response.newSuccess(true);
        return Response.newFail("面试时间不正确！");
    }

    @DeleteMapping("deleteinterview/{interNo}")
    public Response<Boolean> deleteInterviewByNo(@PathVariable int interNo) {
        interviewService.deleteInterviewByNo(interNo);
        return Response.newSuccess(true);
    }
}
